﻿#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAX_STAGE 10
#define LEVEL_MAX 6
#define	LEVEL_MIN 2

int sleep(unsigned x)
{
	clock_t c1 = clock(), c2;

	do
	{
		if ((c2 = clock()) == (clock_t)-1)
			return 0;
	} while (1000*(c2-c1)/CLOCKS_PER_SEC < x);

	return 1;
}

int main()
{
	int stage = 0;
	int level = 0;
	int success = 0;
	int score[MAX_STAGE] = { 0 };
	clock_t beg = 0, end = 0;

	srand((unsigned)time(NULL));

	printf("加一训练开始！！\n");
	printf("来记忆2位数的数值。\n");
	printf("请输入原数值加1后的值。\n");

	do
	{
		printf("要挑战的等级（%d~%d）：", LEVEL_MIN, LEVEL_MAX);
		scanf("%d", &level);
	} while (level < LEVEL_MIN || level > LEVEL_MAX);

	beg = clock();
	for (stage = 0; stage < MAX_STAGE; ++stage)
	{
		int right = 0;
		int ans[LEVEL_MAX] = { 0 };
		int in[2 * LEVEL_MAX] = { 0 };

		printf("第%d关卡开始！！\n", stage + 1);

		for (int i = 0; i < level; ++i)
		{
			ans[i] = rand() % 90 + 10;
			printf("%d ", ans[i]);
		}
		fflush(stdout);
		sleep(300*level);
		printf("\r%*s\r", 3*level, "");

		for (int i = 0; i < level; ++i)
		{
			printf("第%d个数：", i + 1);
			scanf("%d", &in[i]);
		}
		
		for (int i = 0; i < level; ++i)
		{
			if (ans[i] + 1 != in[i])
				printf("× ");
			else
			{
				++right;
				printf("○ ");
			}
		}
		putchar('\n');

		for (int i = 0; i < level; ++i)
		{
			printf("%2d ", ans[i] + 1);
		}
		printf("···答对了%d个。\n", right);
		score[stage] = right;
		success += right;
	}
	end = clock();

	printf("%d个中答对了%d个。\n", level * MAX_STAGE, success);

	for (int i = 0; i < MAX_STAGE; ++i)
	{
		printf("第%d关卡：%d\n", i + 1, score[i]);
	}

	printf("用时%.1f秒。\n", (double)(end-beg)/CLOCKS_PER_SEC);

	return 0;
}